//
//  HZSQLManager.m
//  car4S
//
//  Created by huazi on 14-3-19.
//  Copyright (c) 2014年 huifu. All rights reserved.
//

#import "HZSQLManager.h"
#import <sqlite3.h>
#define kDatabaseName @"DBDinosaur.sqlite3/"

@interface HZSQLManager ()
{
    sqlite3 *Database;
}
@end;
@implementation HZSQLManager
static HZSQLManager *shareSQLManager =nil;

- (NSString *)dataFilePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(
                                                         NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
   // NSLog(@"%@",[documentsDirectory stringByAppendingPathComponent:kDatabaseName]);
    
    return [documentsDirectory stringByAppendingPathComponent:kDatabaseName];
}
+(HZSQLManager *)shareSQLManager
{
    @synchronized(self) {
        if ( shareSQLManager== nil)
        {
            
            // assignment not done here
            shareSQLManager =[[self alloc] init];
            
        }
        
    }
    return shareSQLManager;
}
+(id)allocWithZone:(NSZone *)zone
{
    @synchronized(self) {
        if (shareSQLManager == nil) {
            
            shareSQLManager = [super allocWithZone:zone];
            
            return shareSQLManager; // assignment and return on first allocation
        }
    }
    return nil; //on subsequent allocation attempts
}

- (id) init
{
    if (self =[super init])
    {
    
    }
    return self;
}
// 执行非查询的 sql 语句，后关闭数据库
- (void)execSql:(NSString *)sql
{
    
    //   下面的语句是打开数据库，如果这个路径没有该数据库，就生成一个
    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
        != SQLITE_OK) {
        sqlite3_close(Database);
        NSAssert(0, @"Failed to open database");
    }
    char *err;
    if (sqlite3_exec(Database, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
        sqlite3_close(Database);
        NSLog(@"数据库操作数据失败!");
    }
    sqlite3_close(Database);
}
-(NSMutableArray *)queryNewsFromNewsTable:(NSString *)querysql
{
    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
        != SQLITE_OK) {
        sqlite3_close(Database);
        NSAssert(0, @"Failed to open database");
    }
    NSMutableArray *temparrNews =[[NSMutableArray alloc] init];
    
    
    //    querysql 未要执行的查询语句
    sqlite3_stmt *statement;
    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
    {
        
        //    SQLITE_ROW ＝＝100；
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            
            //    statement后面的数字 n 表示是第（n+1）个字段的信息
            //    int row = sqlite3_column_int(statement, 0);
            
            char *rowData1 = (char *)sqlite3_column_text(statement, 2);
            NSString *Value1 = [[NSString alloc]
                                initWithUTF8String:rowData1];
            char *rowData2 = (char *)sqlite3_column_text(statement, 3);
            NSString *Value2 = [[NSString alloc]
                                initWithUTF8String:rowData2];
            char *rowData3 = (char *)sqlite3_column_text(statement, 4);
            NSString *Value3 = [[NSString alloc]
                                initWithUTF8String:rowData3];
            char *rowData4 = (char *)sqlite3_column_text(statement, 5);
            NSString *Value4 = [[NSString alloc]
                                initWithUTF8String:rowData4];
            char *rowData5 = (char *)sqlite3_column_text(statement, 6);
            NSString *Value5 = [[NSString alloc]
                                initWithUTF8String:rowData5];
            char *rowData6 = (char *)sqlite3_column_text(statement, 7);
            NSString *Value6 = [[NSString alloc]
                                initWithUTF8String:rowData6];
            char *rowData7 = (char *)sqlite3_column_text(statement, 8);
            NSString *Value7 = [[NSString alloc]
                                initWithUTF8String:rowData7];
            char *rowData8 = (char *)sqlite3_column_text(statement, 9);
            NSString *Value8 = [[NSString alloc]
                                initWithUTF8String:rowData8];
            char *rowData9 = (char *)sqlite3_column_text(statement, 10);
            NSString *Value9 = [[NSString alloc]
                                initWithUTF8String:rowData9];
            char *rowData10 = (char *)sqlite3_column_text(statement, 11);
            NSString *Value10 = [[NSString alloc]
                                 initWithUTF8String:rowData10];
            char *rowData11 = (char *)sqlite3_column_text(statement, 12);
            NSString *Value11 = [[NSString alloc]
                                 initWithUTF8String:rowData11];
            
            char *rowData12 = (char *)sqlite3_column_text(statement, 13);
            NSString *Value12 = [[NSString alloc]
                                 initWithUTF8String:rowData12];
            char *rowData13 = (char *)sqlite3_column_text(statement, 14);
            NSString *Value13 = [[NSString alloc]
                                 initWithUTF8String:rowData13];
            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value1,@"isSelf",Value2,@"userId",Value3,@"msgType",Value4,@"content",Value5,@"downloadUrl",Value6,@"timeLength",Value7,@"location",Value8,@"photoUrl",Value9,@"nickName",Value10,@"sendTime",Value11,@"bigpicUrl",Value12,@"smallpicUrl",Value13,@"filePath",nil];
            [temparrNews addObject:tempdic];
            
        }
        sqlite3_finalize(statement);
    }
    sqlite3_close(Database);
    
    return temparrNews;
}
-(NSInteger)queryNoReadNews:(NSString *)querysql {
    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
        != SQLITE_OK) {
        sqlite3_close(Database);
        NSAssert(0, @"Failed to open database");
    }
    NSInteger returnInteger;
    //    querysql 未要执行的查询语句
    sqlite3_stmt *statement;
    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
    {
        
        //    SQLITE_ROW ＝＝100；
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            
            //    statement后面的数字 n 表示是第（n+1）个字段的信息
            //    int row = sqlite3_column_int(statement, 0);
            returnInteger =(NSInteger)sqlite3_column_int(statement, 0);
        }
        sqlite3_finalize(statement);
    }
    sqlite3_close(Database);
    return returnInteger;
}
//-(NSMutableArray *)queryNewsFromNewsTable:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrNews =[[NSMutableArray alloc] init];
//    
//    
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //    int row = sqlite3_column_int(statement, 0);
//            
//            char *rowData1 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 5);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            char *rowData5 = (char *)sqlite3_column_text(statement, 6);
//            NSString *Value5 = [[NSString alloc]
//                                initWithUTF8String:rowData5];
//            char *rowData6 = (char *)sqlite3_column_text(statement, 7);
//            NSString *Value6 = [[NSString alloc]
//                                initWithUTF8String:rowData6];
//            char *rowData7 = (char *)sqlite3_column_text(statement, 8);
//            NSString *Value7 = [[NSString alloc]
//                                initWithUTF8String:rowData7];
//            char *rowData8 = (char *)sqlite3_column_text(statement, 9);
//            NSString *Value8 = [[NSString alloc]
//                                initWithUTF8String:rowData8];
//            char *rowData9 = (char *)sqlite3_column_text(statement, 10);
//            NSString *Value9 = [[NSString alloc]
//                                initWithUTF8String:rowData9];
//            char *rowData10 = (char *)sqlite3_column_text(statement, 11);
//            NSString *Value10 = [[NSString alloc]
//                                 initWithUTF8String:rowData10];
//            char *rowData11 = (char *)sqlite3_column_text(statement, 12);
//            NSString *Value11 = [[NSString alloc]
//                                 initWithUTF8String:rowData11];
//            
//            char *rowData12 = (char *)sqlite3_column_text(statement, 13);
//            NSString *Value12 = [[NSString alloc]
//                                 initWithUTF8String:rowData12];
//            char *rowData13 = (char *)sqlite3_column_text(statement, 14);
//            NSString *Value13 = [[NSString alloc]
//                                 initWithUTF8String:rowData13];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value1,@"isSelf",Value2,@"userId",Value3,@"msgType",Value4,@"content",Value5,@"downloadUrl",Value6,@"timeLength",Value7,@"location",Value8,@"photoUrl",Value9,@"nickName",Value10,@"sendTime",Value11,@"bigpicUrl",Value12,@"smallpicUrl",Value13,@"filePath",nil];
//            [temparrNews addObject:tempdic];
//            
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrNews;
//}
//-(NSMutableArray *)queryNewsFromSessionTable:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    
//    
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //         int row = sqlite3_column_int(statement, 0);
//            char *rowData1 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            char *rowData5 = (char *)sqlite3_column_text(statement, 5);
//            NSString *Value5 = [[NSString alloc]
//                                initWithUTF8String:rowData5];
//            char *rowData6 = (char *)sqlite3_column_text(statement, 6);
//            NSString *Value6 = [[NSString alloc]
//                                initWithUTF8String:rowData6];
//            char *rowData7 = (char *)sqlite3_column_text(statement, 7);
//            NSString *Value7 = [[NSString alloc]
//                                initWithUTF8String:rowData7];
//            char *rowData8 = (char *)sqlite3_column_text(statement, 8);
//            NSString *Value8 = [[NSString alloc]
//                                initWithUTF8String:rowData8];
//            char *rowData9 = (char *)sqlite3_column_text(statement, 9);
//            NSString *Value9 = [[NSString alloc]
//                                initWithUTF8String:rowData9];
//            char *rowData10 = (char *)sqlite3_column_text(statement, 10);
//            NSString *Value10 = [[NSString alloc]
//                                 initWithUTF8String:rowData10];
//            char *rowData11 = (char *)sqlite3_column_text(statement, 11);
//            NSString *Value11 = [[NSString alloc]
//                                 initWithUTF8String:rowData11];
//            
//            char *rowData12 = (char *)sqlite3_column_text(statement, 12);
//            NSString *Value12 = [[NSString alloc]
//                                 initWithUTF8String:rowData12];
//            char *rowData13 = (char *)sqlite3_column_text(statement, 13);
//            NSString *Value13 = [[NSString alloc]
//                                 initWithUTF8String:rowData13];
//            char *rowData14 = (char *)sqlite3_column_text(statement, 14);
//            NSString *Value14 = [[NSString alloc]
//                                 initWithUTF8String:rowData14];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value1,@"isSelf",Value2,@"userId",Value3,@"msgType",Value4,@"content",Value5,@"downloadUrl",Value6,@"timeLength",Value7,@"location",Value8,@"photoUrl",Value9,@"nickName",Value10,@"sendTime",Value11,@"bigpicUrl",Value12,@"smallpicUrl",Value13,@"noReadNum",Value14,@"lastUpdatetime",nil];
//            [temparrSession addObject:tempdic];
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//}
//-(NSMutableArray *)queryProdcutHistoryRecode:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    
//    
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //         int row = sqlite3_column_int(statement, 0);
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            char *rowData1 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"id",Value1,@"name",Value2,@"price",Value3,@"imgPath",nil];
//         
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//}
//
//-(NSMutableArray *)queryKeywordTable:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    
//    
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //         int row = sqlite3_column_int(statement, 0);
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"name",nil];
//            //            ProductDetail *product =[[ProductDetail alloc] initWithDataDic:tempdic];
//            [temparrSession addObject:tempdic];
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//}
//-(NSMutableArray *)queryShopCarTable:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    
//    
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //         int row = sqlite3_column_int(statement, 0);
//            char *rowData0 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            char *rowData1 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 5);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            char *rowData5 = (char *)sqlite3_column_text(statement, 6);
//            NSString *Value5 = [[NSString alloc]
//                                initWithUTF8String:rowData5];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"id",Value1,@"name",Value2,@"price",Value3,@"img_path",Value4,@"gift_name",Value5,@"nums",nil];
//         
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    return temparrSession;
//}
//-(NSMutableArray *)queryDinosaurFargatherList:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    
//    
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //         int row = sqlite3_column_int(statement, 0);
////            (id TEXT PRIMARY KEY , time TEXT,Name TEXT, own TEXT ,peoples TEXT)
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            char *rowData1 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"id",Value1,@"time",Value2,@"Name",Value3,@"own",Value4,@"peoples",nil];
//            ForgatherDetail *forgather =[[ForgatherDetail alloc] initWithDic:tempdic];
//            [temparrSession addObject:forgather];
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//}
//-(NSMutableArray *)queryDinosaurAccountListFromParty_id:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    
//    
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //         int row = sqlite3_column_int(statement, 0);
//            //            (id TEXT PRIMARY KEY , time TEXT,Name TEXT, own TEXT ,peoples TEXT)
//            
//            //    @property (strong, nonatomic)NSString *Aid;       //聚会id+手机号
//            //    @property (strong, nonatomic)NSString *Aown;      //谁的聚会
//            //    @property (strong, nonatomic)NSString *Aparty_id; //聚会Id
//            //    @property (strong, nonatomic)NSString *AName;     //账户名
//            //    @property (strong, nonatomic)NSString *APhone;    //账户手机号
//            //    @property (strong, nonatomic)NSString *Aisadmin;  //是否是管理员自己
//            //    @property (strong, nonatomic)NSString *Apayment； //收款金额
//            //    @property (strong, nonatomic)NSString *AphoneUrl; //图片路径
////            if (self =[super init])
////            {
////                self.Aid =[dic objectForKey:@"id"];
////                self.Aown =[dic objectForKey:@"own"];
////                self.Aparty_id =[dic objectForKey:@"party_id"];
////                self.Apayment =[dic objectForKey:@"payment"];
////                self.APhone =[dic objectForKey:@"Phone"];
////                self.AphoneUrl =[dic objectForKey:@"phoneUrl"];
////                self.AName =[dic objectForKey:@"Name"];
////                self.Aisadmin =[dic objectForKey:@"isadmin"];
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            char *rowData1 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            char *rowData5 = (char *)sqlite3_column_text(statement, 5);
//            NSString *Value5 = [[NSString alloc]
//                                initWithUTF8String:rowData5];
//            char *rowData6 = (char *)sqlite3_column_text(statement, 6);
//            NSString *Value6 = [[NSString alloc]
//                                initWithUTF8String:rowData6];
//            char *rowData7 = (char *)sqlite3_column_text(statement, 7);
//            NSString *Value7 = [[NSString alloc]
//                                initWithUTF8String:rowData7];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"id",Value1,@"own",Value2,@"party_id",Value3,@"Name",Value4,@"Phone",Value5,@"isadmin",Value6,@"payment",Value7,@"phoneUrl",nil];
//            AccountDetail *account =[[AccountDetail alloc] initWithDic:tempdic];
//            [temparrSession addObject:account];
//          
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//}
//-(NSString *)queryAccountName:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSString *returnStr =@"";
//       //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            returnStr =Value0;
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    return returnStr;
//}
//-(NSString *)queryParty_Action_User_GatheringGathering:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSString *returnStr =@"0";
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            returnStr =Value0;
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    return returnStr;
//}
//-(NSMutableArray *)queryConsumeListFormFarogtherId:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    NSString *strPrev =@"";
//    NSString *strCurrent =@"";
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //        @property (strong, nonatomic)NSString *Cid;           //聚会的活动id
//            //        @property (strong, nonatomic)NSString *Cown;
//            //        @property (strong, nonatomic)NSString *Cparty_id;
//            //        @property (strong, nonatomic)NSString *CName;
//            //        @property (strong, nonatomic)NSString *Ctime;
//            //        @property (strong, nonatomic)NSString *Cpeoples;     //该活动参加的人数(占比不为0的人)默认为0
//            //        @property (strong, nonatomic)NSString *Ccharge;             //消费总额
//            //        @property (strong, nonatomic)NSString *Cmerchant;      //商家
////            self.Cid =[dic objectForKey:@"id"];
////            self.Cown =[dic objectForKey:@"own"];
////            self.Cparty_id =[dic objectForKey:@"party_id"];
////            self.CName =[dic objectForKey:@"Name"];
////            self.Ctime =[dic objectForKey:@"time"];
////            self.Cpeoples =[dic objectForKey:@"peoples"];
////            self.Ccharge =[dic objectForKey:@"charge"];
////            self.Cmerchant =[dic objectForKey:@"merchant"];
//
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            char *rowData1 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            char *rowData5 = (char *)sqlite3_column_text(statement, 5);
//            NSString *Value5 = [[NSString alloc]
//                                initWithUTF8String:rowData5];
//            char *rowData6 = (char *)sqlite3_column_text(statement, 6);
//            NSString *Value6 = [[NSString alloc]
//                                initWithUTF8String:rowData6];
//            char *rowData7 = (char *)sqlite3_column_text(statement, 7);
//            NSString *Value7 = [[NSString alloc]
//                                initWithUTF8String:rowData7];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"id",Value1,@"own",Value2,@"party_id",Value3,@"Name",Value4,@"time",Value5,@"peoples",Value6,@"charge",Value7,@"merchant",nil];
//            ConsumeDetail *consume =[[ConsumeDetail alloc] initWithDic:tempdic];
//            strPrev =strCurrent;
//            strCurrent =[Value4 substringToIndex:8];
//            
//            if ([strCurrent isEqualToString:strPrev])
//            {
//                consume.Cfirst =@"0";
//            }
//            else
//            {
//                consume.Cfirst =@"1";
//            }
//            [temparrSession addObject:consume];
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//}
//-(NSMutableArray *)queryParty_Action_UserListFormFarogtherIdAndActionId:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
////            @property (strong, nonatomic)NSString *PAUid;    //(party_id+action_id+user_id)
////            @property (strong, nonatomic)NSString *PAUown;
////            @property (strong, nonatomic)NSString *PAUparty_id;
////            @property (strong, nonatomic)NSString *PAUaction_id;
////            @property (strong, nonatomic)NSString *PAUproportion;   //占比数
////            @property (strong, nonatomic)NSString *PAUuser_id;      //用户的id
//            
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            char *rowData1 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            char *rowData5 = (char *)sqlite3_column_text(statement, 5);
//            NSString *Value5 = [[NSString alloc]
//                                initWithUTF8String:rowData5];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"id",Value1,@"own",Value2,@"party_id",Value3,@"action_id",Value4,@"proportion",Value5,@"user_id",nil];
//            Party_Action_User *party_action_user =[[Party_Action_User alloc] initWithDic:tempdic];
//            [temparrSession addObject:party_action_user];
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//}
//-(NSMutableArray *)queryReceiveMoneySessionListFromParty_id:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//            //    @property (strong, nonatomic)NSString *PAUGid;
//            //    @property (strong, nonatomic)NSString *PAUGown;
//            //    @property (strong, nonatomic)NSString *PAUGparty_id;
//            //    @property (strong, nonatomic)NSString *PAUGgathering;   //收款金额
//            //    @property (strong, nonatomic)NSString *PAUGtimestamp;
//            //    @property (strong, nonatomic)NSString *PAUGuser_id;
////            if (self =[super init])
////            {
////                self.PAUGid =[dic objectForKey:@"id"];
////                self.PAUGown =[dic objectForKey:@"own"];
////                self.PAUGparty_id =[dic objectForKey:@"party_id"];
////                self.PAUGgathering =[dic objectForKey:@"gathering"];
////                self.PAUGtimestamp =[dic objectForKey:@"timestamp"];
////                self.PAUGuser_id =[dic objectForKey:@"user_id"];
//            
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            char *rowData1 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            char *rowData5 = (char *)sqlite3_column_text(statement, 5);
//            NSString *Value5 = [[NSString alloc]
//                                initWithUTF8String:rowData5];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"id",Value1,@"own",Value2,@"party_id",Value3,@"gathering",Value4,@"timestamp",Value5,@"user_id",nil];
//            Party_Actions_Users_Gathering *party_action_user_gathering =[[Party_Actions_Users_Gathering alloc] initWithDic:tempdic];
//            [temparrSession addObject:party_action_user_gathering];
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//
//}
//-(NSString *)queryUserForFargatherTotalPrice:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    float totalPrice =0.0f;
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            totalPrice =totalPrice +[Value0 floatValue];
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    return [NSString stringWithFormat:@"%.2f",totalPrice];
//
//}
//-(NSMutableArray *)queryParty_Action_User_ConsumeListFromFarogtherIdAndAccountId:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSMutableArray *temparrSession =[[NSMutableArray alloc] init];
//    NSString *strPrev =@"";
//    NSString *strCurrent =@"";
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            //    statement后面的数字 n 表示是第（n+1）个字段的信息
//    
//            //        @property (strong, nonatomic)NSString *PAUCid;
//            //        @property (strong, nonatomic)NSString *PAUCown;
//            //        @property (strong, nonatomic)NSString *PAUCparty_id;          //聚会id
//            //        @property (strong, nonatomic)NSString *PAUCaction_id;         //活动id
//            //        @property (strong, nonatomic)NSString *PAUCuser_id;           //用户id
//            //        @property (strong, nonatomic)NSString *PAUCtimestamp;         //消费时间
//            //        @property (strong, nonatomic)NSString *PAUCcharge;            //自己的消费金额
//            //        @property (strong, nonatomic)NSString *PAUCproportion;        //自己的消费占比
//            //        @property (strong, nonatomic)NSString *PAUCtotalproportion;   //活动的总占比的个数
////            self.PAUCid =[dic objectForKey:@"id"];
////            self.PAUCown =[dic objectForKey:@"own"];
////            self.PAUCparty_id =[dic objectForKey:@"party_id"];
////            self.PAUCaction_id =[dic objectForKey:@"action_id"];
////            self.PAUCuser_id =[dic objectForKey:@"user_id"];
////            self.PAUCtimestamp =[dic objectForKey:@"timestamp"];
////            self.PAUCcharge =[dic objectForKey:@"charge"];
////            self.PAUCproportion =[dic objectForKey:@"proportion"];
////            self.PAUCtotalproportion =[dic objectForKey:@"totalproportion"];
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            char *rowData1 = (char *)sqlite3_column_text(statement, 1);
//            NSString *Value1 = [[NSString alloc]
//                                initWithUTF8String:rowData1];
//            char *rowData2 = (char *)sqlite3_column_text(statement, 2);
//            NSString *Value2 = [[NSString alloc]
//                                initWithUTF8String:rowData2];
//            char *rowData3 = (char *)sqlite3_column_text(statement, 3);
//            NSString *Value3 = [[NSString alloc]
//                                initWithUTF8String:rowData3];
//            char *rowData4 = (char *)sqlite3_column_text(statement, 4);
//            NSString *Value4 = [[NSString alloc]
//                                initWithUTF8String:rowData4];
//            char *rowData5 = (char *)sqlite3_column_text(statement, 5);
//            NSString *Value5 = [[NSString alloc]
//                                initWithUTF8String:rowData5];
//            char *rowData6 = (char *)sqlite3_column_text(statement, 6);
//            NSString *Value6 = [[NSString alloc]
//                                initWithUTF8String:rowData6];
//            char *rowData7 = (char *)sqlite3_column_text(statement, 7);
//            NSString *Value7 = [[NSString alloc]
//                                initWithUTF8String:rowData7];
//            char *rowData8 = (char *)sqlite3_column_text(statement, 8);
//            NSString *Value8 = [[NSString alloc]
//                                initWithUTF8String:rowData8];
//            NSMutableDictionary *tempdic =[NSMutableDictionary dictionaryWithObjectsAndKeys:Value0,@"id",Value1,@"own",Value2,@"party_id",Value3,@"action_id",Value4,@"user_id",Value5,@"timestamp",Value6,@"charge",Value7,@"proportion",Value8,@"totalproportion",nil];
//            Party_Action_User_Consume *consume =[[Party_Action_User_Consume alloc] initWithDic:tempdic];
//            strPrev =strCurrent;
//            strCurrent =[Value5 substringToIndex:8];
//            
//            if ([strCurrent isEqualToString:strPrev])
//            {
//                consume.PAUCfirst =@"0";
//            }
//            else
//            {
//                consume.PAUCfirst =@"1";
//            }
//            [temparrSession addObject:consume];
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    
//    return temparrSession;
//
//}
//-(NSString *)queryConsumeNameFromConsumeId:(NSString *)querysql
//{
//    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
//        != SQLITE_OK) {
//        sqlite3_close(Database);
//        NSAssert(0, @"Failed to open database");
//    }
//    NSString *returnStr =@"";
//    //    querysql 未要执行的查询语句
//    sqlite3_stmt *statement;
//    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
//    {
//        
//        //    SQLITE_ROW ＝＝100；
//        while (sqlite3_step(statement) == SQLITE_ROW)
//        {
//            
//            
//            char *rowData0 = (char *)sqlite3_column_text(statement, 0);
//            NSString *Value0 = [[NSString alloc]
//                                initWithUTF8String:rowData0];
//            returnStr =Value0;
//            
//            //  这里得到一行数据后应该是要用一个字典去接收它
//        }
//        sqlite3_finalize(statement);
//    }
//    sqlite3_close(Database);
//    return returnStr;
//}
-(NSMutableArray *)querySearchHistoryTable:(NSString *)querysql{
    if (sqlite3_open([[self dataFilePath] UTF8String], &Database)
        != SQLITE_OK) {
        sqlite3_close(Database);
        NSAssert(0, @"Failed to open database");
    }
    NSMutableArray *temparrNews =[[NSMutableArray alloc] init];
    
    
    //    querysql 未要执行的查询语句
    sqlite3_stmt *statement;
    if (sqlite3_prepare_v2(Database, [querysql UTF8String],-1, &statement, nil) == SQLITE_OK)
    {
        
        //    SQLITE_ROW ＝＝100；
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            
            //    statement后面的数字 n 表示是第（n+1）个字段的信息
            //    int row = sqlite3_column_int(statement, 0);
            
            char *rowData1 = (char *)sqlite3_column_text(statement, 0);
            NSString *Value1 = [[NSString alloc]
                                initWithUTF8String:rowData1];
            [temparrNews addObject:Value1];
            
        }
        sqlite3_finalize(statement);
    }
    sqlite3_close(Database);
    
    return temparrNews;
}

@end
